/**
 * Created by xinhuang on 15/6/9.
 */
(function (angular) {
  'use strict';

  angular.module('controllers.customActivity.realtime')
    .controller('realtimeDisplayController', realtimeDisplayController);

  function realtimeDisplayController($scope, $state, activityManager, realtimeServer, chartService, timedTask) {
    var activityId = Number($state.params.activityId);
    $scope.activityId = activityId;
    $scope.activityManager = activityManager;

    realtimeServer.setActivityId(activityId);

    realtimeServer.activityStateCheck(activityId)
      .success(function (res) {
        activityManager.activtyState = res.state;
        if (res.state !== '1005') {
          timedTask.start();
        }
      });

    $scope.$on('$destroy', function () {
      timedTask.stop();
      chartService.clearInstances();
    });
  }

})(angular);